import { createRouter, createWebHistory, createWebHashHistory, type RouteRecordRaw } from 'vue-router'

const mode = import.meta.env.VITE_ROUTER_MODE;

const routes: RouteRecordRaw[] = [
  {
    path: '/',
    component: () => import('../pages/IndexPage.vue'),
    meta: {
      id: '8a864448910746d9921e61f76ba73480'
    },
    children: [
      {
        path: '',
        name: 'indexRenderPage',
        component: () => import('../pages/RenderPage.vue'),
      },
      {
        path: 'success',
        name: 'previewIndexSuccessPage',
        component: () => import('../pages/SuccessPage.vue')
      },
      {
        path: 'error',
        name: 'previewIndexErrorPage',
        component: () => import('../pages/ErrorPage.vue')
      }
    ]
  },
  {
    path: '/:id',
    component: () => import('../pages/IndexPage.vue'),
    children: [
      {
        path: '',
        name: 'previewRenderPage',
        component: () => import('../pages/RenderPage.vue')
      },
      {
        path: 'success',
        name: 'previewSuccessPage',
        component: () => import('../pages/SuccessPage.vue')
      },
      {
        path: 'error',
        name: 'previewErrorPage',
        component: () => import('../pages/ErrorPage.vue')
      }
    ]
  },
  {
    path: '/:catchAll(.*)',
    name: 'emptyPage',
    component: () => import('../pages/EmptyPage.vue')
  }
]
// 兼容预览模式
const base = window.location.pathname.includes('preview') ? 'myactivity/preview' : (window.location.pathname.includes('myactivity/render') ? 'myactivity/render' : 'render')
const router = createRouter({
  history: mode === 'hash' ? createWebHashHistory(base) : createWebHistory(base),
  routes
})

export default router
